package com.emm.yixun.mobile.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.model.GetCustomerList.CustomerList;

import java.util.ArrayList;

public class NotSignedAdapter extends BaseAdapter {

	public boolean isv = false;

	Context context;

	ArrayList<CustomerList> list;

	public NotSignedAdapter(Context context, ArrayList<CustomerList> list) {
		this.context = context;
		this.list = list;
	}

	public void setDate(ArrayList<CustomerList> list) {
		this.list = list;
		notifyDataSetChanged();
	}

	public boolean getIsv(boolean isv) {
		this.isv = isv;
		return isv;
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	// @Override
	// public View getView(final int position, View convertView, ViewGroup
	// parent) {
	// ViewHoudlerCustomer v = null;
	// if (convertView == null) {
	// convertView =
	// LayoutInflater.from(context).inflate(R.layout.notsigned_item, null);
	// v = new ViewHoudlerCustomer();
	// v.time = (TextView) convertView.findViewById(R.id.time);
	// v.type_view = (TextView) convertView.findViewById(R.id.type_view);
	// v.user_name = (TextView) convertView.findViewById(R.id.user_name);
	// v.select_image = (ImageView) convertView.findViewById(R.id.select_image);
	// v.start_image = (ImageView) convertView.findViewById(R.id.start_image);
	// convertView.setTag(v);
	// } else {
	// v = (ViewHoudlerCustomer) convertView.getTag();
	// }
	// v.time.setText(list.get(position).getCreateTime());
	// v.type_view.setText(list.get(position).getCustomerOrigin());
	// v.user_name.setText(list.get(position).getCustomerName() + "(" +
	// list.get(position).getIntentionLevel() + ")");
	// if (isv) {
	// v.select_image.setVisibility(View.VISIBLE);
	// } else {
	// v.select_image.setVisibility(View.GONE);
	// }
	// if (list.get(position).isIsselect()) {
	// v.select_image.setImageResource(R.drawable.ico_selt);
	// } else {
	// v.select_image.setImageResource(R.drawable.ico_delt_no);
	// }
	// v.select_image.setOnClickListener(new OnClickListener() {
	// @Override
	// public void onClick(View v) {
	// if (list.get(position).isIsselect()) {
	// list.get(position).setIsselect(false);
	// } else {
	// list.get(position).setIsselect(true);
	// }
	// notifyDataSetChanged();
	// }
	// });
	// if ("1".equals(list.get(position).getStar())) {
	// v.start_image.setVisibility(View.GONE);
	// } else {
	// v.start_image.setVisibility(View.GONE);
	// }
	//
	//
	//
	// return convertView;
	// }

	// public static class ViewHoudlerCustomer {
	//
	// ImageView select_image, start_image;
	//
	// TextView user_name, type_view, time;
	//
	// }

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHoudlerCustomer v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.customer_item2, null);
			v = new ViewHoudlerCustomer();
			v.do_type = (TextView) convertView.findViewById(R.id.do_type);
			v.time = (TextView) convertView.findViewById(R.id.time);
			v.type_view = (TextView) convertView.findViewById(R.id.type_view);
			v.user_name = (TextView) convertView.findViewById(R.id.user_name);
			v.select_image = (ImageView) convertView.findViewById(R.id.select_image);
			v.start_image = (ImageView) convertView.findViewById(R.id.start_image);
			v.lv_name = (TextView) convertView.findViewById(R.id.lv_name);
			v.Belonging_people = (TextView) convertView.findViewById(R.id.Belonging_people);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlerCustomer) convertView.getTag();
		}

		v.Belonging_people.setText(EmmApplication.isNull(list.get(position).getAttributionName()) ? list.get(position)
				.getAttributionName() : "");
		v.do_type.setText(EmmApplication.isNull(list.get(position).getCustomerStatus()) ? list.get(position)
				.getCustomerStatus() : "");
		v.time.setText(EmmApplication.isNull(list.get(position).getCreateTime()) ? list.get(position).getCreateTime() : "");
		v.type_view.setText(EmmApplication.isNull(list.get(position).getCustomerOrigin()) ? list.get(position)
				.getCustomerOrigin() : "");
		v.user_name.setText(EmmApplication.isNull(list.get(position).getCustomerName()) ? list.get(position)
				.getCustomerName() : "");
		v.lv_name.setText((EmmApplication.isNull(list.get(position).getIntentionLevel()) ? "("
				+ list.get(position).getIntentionLevel() + ")" : " "));
		if (isv) {
			v.select_image.setVisibility(View.VISIBLE);
		} else {
			v.select_image.setVisibility(View.GONE);
		}
		if (list.get(position).isIsselect()) {
			v.select_image.setImageResource(R.drawable.ico_selt);
		} else {
			v.select_image.setImageResource(R.drawable.ico_delt_no);
		}
		if ("1".equals(list.get(position).getStar())) {
			v.start_image.setVisibility(View.VISIBLE);
		} else {
			v.start_image.setVisibility(View.GONE);
		}
		v.select_image.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (list.get(position).isIsselect()) {
					list.get(position).setIsselect(false);
				} else {
					list.get(position).setIsselect(true);
				}
				notifyDataSetChanged();
			}
		});

		return convertView;
	}

	public static class ViewHoudlerCustomer {

		ImageView select_image, start_image;

		TextView user_name, type_view, do_type, time, lv_name, Belonging_people;

	}

}
